package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.UserCollect;
import cn.wolfcode.trip.base.domain.UserLike;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.mapper.UserCollectMapper;
import cn.wolfcode.trip.base.service.ICollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/11/16.
 */
@Service
public class CollectServiceImpl implements ICollectService {

    @Autowired
    private UserCollectMapper collectMapper;
    @Autowired
    private StrategyMapper strategyMapper;


    @Override
    public UserCollect get(Long userId,Long collectId,Integer type) {
        return collectMapper.getCollect(userId,collectId,type);
    }

    @Override
    public Integer save(UserCollect uc) {
        collectMapper.insert(uc);
        if(uc.getType()== UserCollect.TYPE_STRATEGY) {
            strategyMapper.addOneCollect(uc.getCollectId());
            Integer collects = strategyMapper.selectByPrimaryKey(uc.getCollectId()).getCollects();
            return collects;
        }
        return uc.getType()+11;//
    }

    @Override
    public Integer delete(Long userId,Long collectId,Integer type) {
        collectMapper.deleteCollect(userId,collectId,type);
        if(type==UserCollect.TYPE_STRATEGY){
            strategyMapper.delOneCollect(collectId);
            collectMapper.deleteCollect(userId,collectId,type);
            return strategyMapper.selectByPrimaryKey(collectId).getCollects();
        }
        collectMapper.deleteCollect(userId,collectId,type);
        return type+12;//
    }

    @Override
    public List<UserCollect> getUserCollectList(Long userId, Integer type) {
        return null;
    }
}
